package com.tpp.threat_perception_platform.controller;

import com.tpp.threat_perception_platform.param.AssetsParam;
import com.tpp.threat_perception_platform.param.HotfixParam;
import com.tpp.threat_perception_platform.param.MyParam;
import com.tpp.threat_perception_platform.param.ThreatParam;
import com.tpp.threat_perception_platform.response.ResponseResult;
import com.tpp.threat_perception_platform.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HostController {
    @Autowired
    private HostService hostService;

    @Autowired
    private AccountService accountService;

    @Autowired
    private AppService  appService;

    @Autowired
    private ServiceService  serviceService;

    @Autowired
    private ProcessService processService;
    @Autowired
    private HotfixService hotfixService;
    @Autowired
    private WeakPwdService weakPwdService;
    @Autowired
    private HostAppVulService hostAppVulService;

    @Autowired
    private  HostVulService hostVulService;
    @Autowired
    private HostSystemVulService hostSystemVulService;

    @Autowired
    private CveService cveService;
    /**
     * 主机列表
     * @param param
     * @return
     */
    @PostMapping("/host/list")
    public ResponseResult hostList(MyParam param){return hostService.hostList(param);}
    /**
     * 这个/host/list/2接口返回只带有mac和host那么的Host
     * 用于前端下拉框的数据
     * @return
     */
    @PostMapping("/host/list/2")
    public ResponseResult<?> list() {
        return hostService.list();
    }
    @PostMapping("/host/updateLogSyncStatus")
    public ResponseResult updateLogSyncStatus(@RequestParam("macAddress") String macAddress, @RequestParam("status") Integer status) {
        return hostService.updateLogSyncStatus(macAddress, status);
    }

//    /**
//     * 发送日志同步消息到队列
//     */
//    @PostMapping("/host/sendLogSyncMessage")
//    public ResponseResult sendLogSyncMessage(@RequestParam("macAddress") String macAddress, @RequestParam("status") Integer status) {
//        return hostService.sendLogSyncMessage(macAddress, status);
//    }

    /**
     * 实现日志同步
     */
    @PostMapping("/host/lohSync")
    public ResponseResult logSync(@RequestParam("macAddress") String macAddress){

        return hostService.logSync(macAddress);
    }


    /**
     * 删除用户
     * @param
     * @return
     */
    @PostMapping("/host/delete")
    public ResponseResult hostEdit(@RequestParam("ids[]") Integer[] ids){
        return hostService.delete(ids);
    }


    @PostMapping("/host/assetsDiscovery")
    public ResponseResult assetsDiscovery(@RequestBody AssetsParam param){
        return hostService.assetsDiscovery(param);
    }
    @PostMapping("/host/threatDiscovery")
    public ResponseResult threatDiscovery(@RequestBody ThreatParam param){
        return hostService.threatDiscovery(param);
    }
    /**
     * 热补丁发现
     * @param param
     * @return
     */
    @PostMapping("/host/hotfixDiscovery")
    public ResponseResult hotfixDiscovery(@RequestBody HotfixParam param){
        return hostService.hotfixDiscovery(param);
    }

    /**
     * 账号列表
     * @param param
     * @param macAddress
     * @return
     */
    @PostMapping("/account/list")
    public ResponseResult accountList(MyParam param,@RequestParam("macAddress")String macAddress){
        param.setMacAddress(macAddress);
        return accountService.accountList(param);}

    /**
     * 应用列表
     * @param param
     * @return
     */
    @PostMapping("/app/list")
    public ResponseResult appList(MyParam param,@RequestParam("macAddress")String macAddress){
        param.setMacAddress(macAddress);
        return appService.appList(param);}

    /**
     * 服务列表
     * @param param
     * @return
     */
    @PostMapping("/service/list")
    public ResponseResult serviceList(MyParam param,@RequestParam("macAddress")String macAddress){

        param.setMacAddress(macAddress);
        return serviceService.serviceList(param);}


    /**
     *
     * 进程列表
     * @param param
     * @return
     */
    @PostMapping("/process/list")
    public ResponseResult processList(MyParam param,@RequestParam("macAddress")String macAddress){

        param.setMacAddress(macAddress);
        return processService.processList(param);}


    /**
     * 热补丁列表
     * @param param
     * @return
     */
    @PostMapping("/hotfix/list")
    public ResponseResult hotfixList(MyParam param, @RequestParam(required = false) String macAddress) {
        if (macAddress != null && !macAddress.isEmpty()) {
            param.setMacAddress(macAddress);
        }
        return hotfixService.hotfixList(param);
    }
    /**
     * 弱口令列表
     * @param param
     * @return
     */

    @PostMapping("/weakPwd/list")
    public ResponseResult weakPwdList(MyParam param, @RequestParam(required = false) String macAddress) {
        // 只有当macAddress不为null时才设置
        if (macAddress != null && !macAddress.isEmpty()) {
            param.setMacAddress(macAddress);
        }
        return weakPwdService.weakPwdList(param);
    }
    /**
     * 应用漏洞列表
     * @param param
     * @return
     */
    @PostMapping("/appVul/list")
    public ResponseResult appVulList(MyParam param, @RequestParam(required = false) String macAddress) {
        if (macAddress != null && !macAddress.isEmpty()) {
            param.setMacAddress(macAddress);
        }
        return hostAppVulService.hostAppVulList(param);
    }

    /**
     * 弱口令列表
     * @param param
     * @return
     */
    @PostMapping("/vul/list")
    public ResponseResult vulList(MyParam param, @RequestParam(required = false) String macAddress) {
        // 只有当macAddress不为null时才设置
        if (macAddress != null && !macAddress.isEmpty()) {
            param.setMacAddress(macAddress);
        }
        return hostVulService.hostVulList(param);
    }

    @PostMapping("/systemVul/list")
    public ResponseResult systemVulList(MyParam param, @RequestParam(required = false) String macAddress) {
        if (macAddress != null && !macAddress.isEmpty()) {
            param.setMacAddress(macAddress);
        }
        return hostSystemVulService.hostSystemVulList(param);
    }


    @PostMapping("/cve/detail")
    public ResponseResult cveDetail(@RequestParam(value = "hotfixId", required = false) String hotfixId) {
        if(hotfixId == null || hotfixId.isEmpty()) {
            return new ResponseResult<>(1001, "hotfixId参数不能为空");
        }
        return cveService.cveDetail(hotfixId);
    }





}
